package com.zzd.controller;

import com.zzd.pojo.Admin;
import com.zzd.service.AdminService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/admin")
//jsp共有目录
public class AdminAction {
    @Resource
    AdminService adminService;
    @RequestMapping("/login")
    public String login(String name,String pwd,HttpServletRequest request){
        Admin admin = adminService.login(name, pwd);
//        调用service找到了返回admin，买找到 null
        if(admin!=null){
//            找到了把admin给前端，跳转到主页 视图解析器直接main
            request.setAttribute("admin",admin);
            return "main";
        }
        else {
            request.setAttribute("errmsg","用户名或密码错误");
            return "login";
        }
    }
}
